package br.com.werp.regras.geral.integracao;

import br.com.werp.regras.geral.util.Constantes;
import br.com.werp.regras.geral.vos.tabelas.Video;

import java.sql.Connection;

import java.util.List;
import java.util.ResourceBundle;


/**
 * @author Candido
 * Criado em  11/01/2005
 */
public class VideoDAO extends MasterDAO {
    private static VideoDAO videoDAO;

    /**
     * @param banco
     * @throws Exception
     */
    private VideoDAO(String banco) throws Exception {
        super(banco);
    }

    public static VideoDAO getPlacaVideoDAO() throws Exception {
        if (videoDAO == null) {
            ResourceBundle bundle = ResourceBundle.getBundle(Constantes.CONFIG);
            videoDAO = new VideoDAO(bundle.getString(Constantes.BANCO));
        }

        return videoDAO;
    }

    /**
     * @param videoId
     * @return
     * @throws Exception
     */
    public Video obterVideo(String videoId) throws Exception {
        return obterVideo(getConexao(), videoId);
    }

    /**
     * @param conexao
     * @param videoId
     * @return
     * @throws Exception
     */
    public Video obterVideo(Connection conexao, String videoId)
        throws Exception {
        Connection conn = null;

        try {
            conn = (Connection) conexao;

            List l = preencheVO(conn, new Video(), " vido_id = " + videoId);

            if (l.isEmpty()) {
                return null;
            }

            return (Video) l.get(0);
        } catch (Exception e) {
            throw e;
        } finally {
            if (conn.getAutoCommit()) {
                liberaConeccao(conn);
            }
        }
    }
}
